<?php

namespace Util;
class Excel
{
    /**
     * 设置Excel表头
     * @param $file_name
     * @param $header
     */
    public static function setExcelHeader($file_name, $header)
    {
        set_time_limit(60);
        ini_set('memory_limit', '512M');
        echo chr(0xEF) . chr(0xBB) . chr(0xBF);
        $full_name = $file_name . date('YmdHis') . ".csv"; //文件名
        header("<meta http-equiv=\"content-type\" content=\"text/html;charset=uft-8\">");
        header("Content-Type: application/vnd.ms-excel");
        header("Expires:0");
        header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
        header("content-disposition: attachment;filename=" . $full_name);
        if (!empty($header)) {
            echo implode(',', $header). "\r\n";
        }
    }

    public static function setRow($row_data)
    {
        if (!empty($row_data)) {
            $row_data_deal = array();
            foreach ($row_data as $key => $value) {
                $value_deal = str_replace(array("\r\n", "\n", "\r", ","), ' ', $value);
                $row_data_deal[$key] = $value_deal;
            }
            echo implode(',', $row_data_deal) . "\r\n";
        }
    }
}